package com.oasys.config;

import com.oasys.interceptor.TokenInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Description: TODO
 * @Author: mis_wu
 * @Date: 2022/5/12
 **/
@Configuration
public class TokenInterceptorMvcConfig implements WebMvcConfigurer {

    /**
     * 项目根路径
     */
    private static final String OA_API = "/oasys";
    /**
     * 用户登录路径
     */
    private static final String OA_API_USER = "/oasys/user";

    /**
     * 需要拦截的路径，/**表示需要拦截所有请求
     */
    private final String[] addPathPatterns={"/**"};
    /**
     * 不需要拦截的路径
     * 获取验证码
     * 登录
     */
    private final String [] excludePathPatterns ={
            "/saveFiles/**",
            "/error",
            OA_API+"/doc.html"
    };

    @Autowired
    private TokenInterceptor tokenInterceptor;

    /**
     * 加载拦截器
     * @param registry reg
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(tokenInterceptor)
                .addPathPatterns(addPathPatterns)
                .excludePathPatterns(excludePathPatterns);
    }
}
